package com.hongxun.design;

import android.content.Context;
import android.content.Intent;

import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.utils.FragmentUtil;
import com.hongxun.design.utils.notification.NotificationUtil;
import com.umeng.message.UmengMessageService;
import com.umeng.message.entity.UMessage;

import org.android.agoo.common.AgooConstants;
import org.json.JSONObject;


/**
 * Created by zerdoor_pc .
 * author:dc
 * 2016/10/29.
 */
public class MyPushIntentService extends UmengMessageService {
    private final String TAG = MyPushIntentService.class.getName();

    @Override
    public void onMessage(Context context, Intent intent) {
        try {
            //可以通过MESSAGE_BODY取得消息体
            String message = intent.getStringExtra(AgooConstants.MESSAGE_BODY);
            UMessage msg = new UMessage(new JSONObject(message));
            MyLog.L(MString.SUCCESSED + "message=" + message);      //消息体
            MyLog.L(MString.SUCCESSED + "custom=" + msg.custom);    //自定义消息的内容
            MyLog.L(MString.SUCCESSED + "title=" + msg.title);      //通知标题
            MyLog.L(MString.SUCCESSED + "text=" + msg.text);        //通知内容

            MyApp.addRedPoint();
            NotificationUtil.getinstence().inIt(msg.title, msg.text,msg.custom);
            try {
                FragmentUtil.getIntence(MyApp.activity).projectFragment.onRefresh();
                FragmentUtil.getIntence(MyApp.activity).homeFragment.Refresh();
            }catch (Exception e){}
        } catch (Exception e) {
            MyLog.L(MString.SUCCESSED + e.getMessage());
        }
    }
}

